package com.itheima.service.serviceImpl;

import com.itheima.domain.CheckItem;
import com.itheima.domain.PageBean;
import com.itheima.domain.R;
import com.itheima.mapper.CheckitemMapper;
import com.itheima.service.CheckitemService;
import com.itheima.util.PageUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CheckitemServiceImpl implements CheckitemService {
    @Autowired
    private CheckitemMapper checkitemMapper;

    @Override
    public Map<String,Object> findPage(PageBean pageBean) {
        Integer pageSize = pageBean.getPageSize();
        Integer currentPage = pageBean.getCurrentPage();
        String query = pageBean.getQueryString();
        List<CheckItem> list = checkitemMapper.findPage((currentPage-1)*pageSize, pageSize,query);
        Integer count = checkitemMapper.count(query);
        Map<String,Object> map = new HashMap<>();
        map.put("rows",list);
        map.put("total",count);
        return map;
    }

    @Override
    public void addCheck(CheckItem checkItem) {
        checkitemMapper.addCheck(checkItem);
    }

    @Override
    public void deleteCheck(Integer id) {
        checkitemMapper.deleteCheck(id);
    }

    @Override
    public CheckItem getCheck(Integer id) {
        return checkitemMapper.getCheck(id);
    }

    @Override
    public void updateCheck(CheckItem checkItem) {
        checkitemMapper.updateCheck(checkItem);
    }
}
